import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;


public class Ex2_3 {

	HashMap<String, Integer> hmasses;

	public Ex2_3(){
		hmasses = new HashMap<String, Integer>();
		loadMasses("C:\\Users\\josemfer\\Downloads\\integer_mass_table.txt");
	}

	private void loadMasses(String file) 
	{		
		try {
			HashMap<String, String> hm = new HashMap<String, String>();
			BufferedReader reader = new BufferedReader( new FileReader (file));
			String         line = null;				
			while( ( line = reader.readLine() ) != null ) {			
				String[] l = line.split("\\s+");
				hmasses.put(l[0],Integer.valueOf(l[1]));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 			
	}	

	
	public ArrayList<String> getSubpeptides(String peptide) {
		ArrayList<String> sub = new ArrayList<String>();
		int n = peptide.length();
		for (int i=1;i<n;i++) {
			for (int j=0;j<n; j++) {
				sub.add((peptide+peptide).substring(j, j+i));
				//System.out.println((peptide+peptide).substring(j, j+i));
			}
		}
		return sub;		
	}

	private Integer getMass(String subpep) {
		int sum = 0;
		for (int i=0;i<subpep.length();i++) {			
			Integer mass = hmasses.get(String.valueOf(subpep.charAt(i)));			
			sum += mass;
		}
		return sum;
	}

	public static void main(String args[]) {	
		try {
			Ex2_3 e = new Ex2_3();
			String peptide = "VKYEAYGPQCLDS";
			//String peptide = KmerCounter.readFile("C:\\Users\\josemfer\\Downloads\\B_brevis.txt").trim();	
			ArrayList<String> sublist = e.getSubpeptides(peptide);
			System.out.print(0+  " ");
			for (String s : sublist) {
				System.out.print(e.getMass(s) + " ");
			}
			System.out.println(e.getMass(peptide));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

